﻿using System;

namespace WITD
{
    /// <summary>
    /// Supports progress reporting.
    /// </summary>
    public class ImportProgress
    {
        private const int DefaultNumOperations = 4;
        private const int MinValue = 0;
        private int MaxValue;
        private bool _useLog;
        private String _sourceProject;
        private String _currentproject;
        private String _currentWIT;
        private int _percentComplete;
        private String _statusText;
        private bool _hasErrors;
        private Exception _currentError;
        private int _numOps;
        private int _numIncs = 0;
        private String _formatString;
        private String _sourceCollection;
        private String _targetCollection;

        /// <summary>
        /// The Uri of the source project Collection
        /// </summary>
        public String SourceCollection
        {
            get
            {
                return _sourceCollection;
            }
            set
            {
                _sourceCollection = value;
            }
        }

        /// <summary>
        /// The Uri of the target project Collection
        /// </summary>
        public String TargetCollection
        {
            get
            {
                return _targetCollection;
            }
            set
            {
                _targetCollection = value;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public int Complete
        { get { return _numOps; } }

        /// <summary>
        /// A String of text intended to be used by String.Format method. Placeholders need to be uniform 
        /// in each format string used so the same information is inserted correctly, when used, in each instance.
        /// <para></para>
        /// <para></para>
        /// It is perfectly fine for a format string to have only placeholders for 0,4 and 5 even when all 6 (or whatever number of) 
        /// data items are passed to String.Format().
        /// </summary>
        public String FormatString
        {
            get
            {
                return _formatString;
            }
            set
            {
                _formatString = value;
            }
        }

        /// <summary>
        /// Denotes whether to log execution.
        /// </summary>
        public bool UseLog
        {
            get
            {
                return _useLog;
            }
            set
            {
                _useLog = value;
            }
        }

        /// <summary>
        /// Denotes whether the current progress update is an error.
        /// </summary>
        public bool HasErrors
        {
            get
            {
                return _hasErrors;
            }
            set
            {
                _hasErrors = value;
            }
        }

        /// <summary>
        /// The Exception object instance if one occurred for the current update. Otherwise null.
        /// </summary>
        public Exception CurrentError
        {
            get
            {
                return _currentError;
            }
            set
            {
                _currentError = value;
            }
        }

        /// <summary>
        /// The actual execution action being performed, such as Copying iterations...
        /// </summary>
        public String StatusText
        {
            get
            {
                return _statusText;
            }
            set
            {
                _statusText = value;
            }
        }

        /// <summary>
        /// The name of the source team project
        /// </summary>
        public String SourceProject
        {
            get
            {
                return _sourceProject;
            }
            set
            {
                _sourceProject = value;
            }
        }

        /// <summary>
        /// The name of the current target team project
        /// </summary>
        public String CurrentProject
        {
            get
            {
                return _currentproject;
            }
            set
            {
                _currentproject = value;
            }
        }

        /// <summary>
        /// The name of the WIT currently being manipulated.
        /// </summary>
        public String CurrentWIT
        {
            get
            {
                return _currentWIT;
            }
            set
            {
                _currentWIT = value;
            }
        }

        /// <summary>
        /// The current progress of execution.
        /// </summary>
        public int PercentComplete
        {
            get
            {
                return _percentComplete;
            }
            set
            {
                _percentComplete = value;
            }
        }
                
        /// <summary>
        /// Constructor: sets the initial state of the object to begin progress reporting.
        /// </summary>
        /// <param name="numOps">The number of individual reportable operations to be executed.</param>
        public ImportProgress(int numOps)
        {
            _percentComplete = 0;
            _numOps = numOps;
            MaxValue = _numOps;
        }
      
        /// <summary>
        /// Increments the progress by one and returns the new value.
        /// </summary>
        /// <returns></returns>
        public Int32 Inc()
        {
            //how many times has inc been called?
            _numIncs++;
            _percentComplete = _numIncs;
            
            return _percentComplete;
        }
    }
}
